#include <iostream>
#include <cmath>
#include <vector>
#include <fstream>
#include <random>
#include "Bezier.hpp"
using namespace std;
const double PI = 3.14159;


int main() {
    vector<int> ms = {10, 40, 160};
    for (int i = 0; i < 3; i++) {
        int m = ms[i];
        Point* pm = new Point[m + 1];
        for (int j = 0; j <m; j++) {
            double t = j*1.0/m; // 生成随机数 t
            pm[j].x = sqrt(3)*sin(2*PI*t);
            if (pm[j].x == 0) {
                delete[] pm; // 释放内存
                return 1;
            }
            pm[j].y = 2.0 / 3.0 * (sqrt(3 - pow(pm[j].x, 2)) + sqrt(abs(pm[j].x)));
        }

        pm[m].x = 0;
        pm[m].y = 0;
        // 将贝塞尔曲线的点写入文件
        string filename = "bezier_" + to_string(m) + ".dat";
        ofstream out(filename);
        if (!out.is_open()) {
            cerr << "Failed to open file: " << filename << endl;
            return 1;
        }
        bezier_point(pm, m, out);
        out.close();

        if (out.fail()) {
            cerr << "Error writing to file: " << filename << endl;
            return 1;
        }

        delete[] pm;
    }

    return 0;
}